﻿using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
using System.Windows.Media.Imaging;
using System.Windows.Controls;

namespace LuanVanProject
{
    #region HeaderToImageConverter

    [ValueConversion(typeof(string), typeof(bool))]
    public class HeaderToImageConverter : IValueConverter
    {
        public static HeaderToImageConverter Instance = new HeaderToImageConverter();

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value != null)
            {

                string title = value as string;
                if ((title).Contains(@".ppt") || (title).Contains(@".pptx"))
                {
                    Uri uri = new Uri("pack://application:,,,/Images/ppt.jpg");
                    BitmapImage source = new BitmapImage(uri);
                    return source;
                }
                if ((title).Contains(@".doc") || (title).Contains(@".docx"))
                {
                    Uri uri = new Uri("pack://application:,,,/Images/word.jpg");
                    BitmapImage source = new BitmapImage(uri);
                    return source;
                }
                if ((title).Contains(@"pdf"))
                {
                    Uri uri = new Uri("pack://application:,,,/Images/pdffile.jpg");
                    BitmapImage source = new BitmapImage(uri);
                    return source;
                }
                if ((title).Contains(@"bmp"))
                {
                    Uri uri = new Uri("pack://application:,,,/Images/bmpfile.jpg");
                    BitmapImage source = new BitmapImage(uri);
                    return source;
                }
                if ((title).Contains(@"png"))
                {
                    Uri uri = new Uri("pack://application:,,,/Images/pngfile.jpg");
                    BitmapImage source = new BitmapImage(uri);
                    return source;
                }
                if ((title).Contains(@"jpg"))
                {
                    Uri uri = new Uri("pack://application:,,,/Images/jpgfile.jpg");
                    BitmapImage source = new BitmapImage(uri);
                    return source;
                }
                else
                {

                    Uri uri = new Uri("pack://application:,,,/Images/unknow_file.jpg");
                    BitmapImage source = new BitmapImage(uri);
                    return source;
                }
            }
            else
            {
                return null;
            }
        }
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotSupportedException("Cannot convert back");
        }
    }

    #endregion // DoubleToIntegerConverter


}